#ifndef __LORA_H
#define __LORA_H

#include <stdint.h>

#define USART_TX_BUFFER_SIZE            256
#define USART_RX_BUFFER_SIZE            256

typedef enum __lora_mode{LORA_M0, LORA_M1, LORA_M2, LORA_M3}LoraMode;

extern usart_type *mb_usart;

extern uint8_t usart2_tx_buffer[];
extern uint32_t usart2_tx_counter;
extern uint32_t usart2_tx_buffer_size;

extern uint8_t usart2_rx_buffer[];
extern uint32_t usart2_rx_counter;
extern uint32_t usart2_rx_buffer_size;
extern uint32_t usart2_rx_time;

extern uint8_t usart1_tx_buffer[];
extern uint32_t usart1_tx_counter;
extern uint32_t usart1_tx_buffer_size;

extern uint8_t usart1_rx_buffer[];
extern uint32_t usart1_rx_counter;
extern uint32_t usart1_rx_buffer_size;
extern uint32_t usart1_rx_time;

extern LoraMode loraMode;
extern uint8_t loraRegRespond;
extern uint8_t loraNeedReconfig;
extern uint8_t outputOpen;
extern uint8_t outputClose;

int enterMode0(void);   // 0: success; -1: fail
int enterMode1(void);   // 0: success; -1: fail
int enterMode3(void);   // 0: success; -1: fail

int setRegAddr(unsigned short addr);
int setRegCh(unsigned char ch);
int setRegCrypt(unsigned short crypt);
int configLora(void);   // 0: success; -1: fail

void respondConfigData(void);

void respondDevAddr(uint8_t func);
void respondBaudRate(uint8_t func);
void respondParity(uint8_t func);
void respondLoraAddr(uint8_t func);
void respondLoraCh(uint8_t func);
void respondLoraCrypt(uint8_t func);
void respondOpen(uint8_t func);
void respondClose(uint8_t func);

void testUart1Tx(void);

#endif // __LORA_H
